/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgLevelItemSubmit
    {
        private readonly Dictionary<int, CfgLevelItemSubmit> _dataMap;
        private readonly List<CfgLevelItemSubmit> _dataList;


        public TbCfgLevelItemSubmit(ByteBuf _buf)
        {
            //first read common data
            _TbCommonLevelItemSubmit _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonLevelItemSubmit(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgLevelItemSubmit>(size * 3 / 2);
            _dataList = new List<CfgLevelItemSubmit>(size);

            for (int i = 0; i < size; i++)
            {
                CfgLevelItemSubmit _v;
                _v = CfgLevelItemSubmit.DeserializeCfgLevelItemSubmit(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgLevelItemSubmit> DataMap => _dataMap;
        public IReadOnlyList<CfgLevelItemSubmit> DataList => _dataList;

        public CfgLevelItemSubmit Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgLevelItemSubmit] config not found,id:" + key.ToString());

            return null;
        }

        public CfgLevelItemSubmit GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "levelitemsubmit";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgLevelItemSubmit LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgLevelItemSubmit(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgLevelItemSubmit
    {
        private CfgLevelItemSubmit(ByteBuf _buf, _TbCommonLevelItemSubmit _commonData)
        {
            Id = _buf.ReadInt();
            Remark = _buf.ReadString();
            { int dataIndex = _buf.ReadInt() - 1; CustomizedDes = _commonData._field0[dataIndex]; }
            Type = (ItemSubmitType)(_buf.ReadInt());
            { int dataIndex = _buf.ReadInt() - 1; AllowItem = _commonData._field1[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; JudgeID = _commonData._field2[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; FailServices = _commonData._field3[dataIndex]; }
            IsSuccessCostItem = _buf.ReadBool();
            IsFailCostItem = _buf.ReadBool();

            PostInit();
        }

        internal static CfgLevelItemSubmit DeserializeCfgLevelItemSubmit(ByteBuf _buf, _TbCommonLevelItemSubmit _commonData)
        {
            return new CfgLevelItemSubmit(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 策划备注 ---- 编辑器专用
        /// </summary>
        private string Remark { get; set; }
        /// <summary>
        /// 自定义提示
        /// </summary>
        public string CustomizedDes { get; private set; }
        /// <summary>
        /// 提交类型
        /// </summary>
        public ItemSubmitType Type { get; private set; }
        /// <summary>
        /// 偶数index为itemcid,作为key,奇数index为需要的数量，作为value得到的map
        /// </summary>
        public IReadOnlyDictionary<int, int> AllowItem { get; private set; }
        /// <summary>
        /// 提交成功组合判断
        /// </summary>
        public IReadOnlyList<int> JudgeID { get; private set; }
        /// <summary>
        /// 提交失败后执行服务
        /// </summary>
        public IReadOnlyList<int> FailServices { get; private set; }
        /// <summary>
        /// 提交成功后是否删除道具
        /// </summary>
        public bool IsSuccessCostItem { get; private set; }
        /// <summary>
        /// 提交失败后是否删除道具
        /// </summary>
        public bool IsFailCostItem { get; private set; }


        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonLevelItemSubmit
    {

        internal IReadOnlyList<string> _field0 { get; private set; }
        internal IReadOnlyList<IReadOnlyDictionary<int, int>> _field1 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field2 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field3 { get; private set; }
        internal _TbCommonLevelItemSubmit(ByteBuf _buf)
        {
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field0 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new Dictionary<int, int>[__n0]; _field1 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ Dictionary<int, int> __v0; { int __n1 = _buf.ReadSize(); var __f1 = new Dictionary<int, int> (__n1 * 3 / 2); __v0 = __f1 ; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ) { int __k1; __k1 = _buf.ReadInt(); int __v1; __v1 = _buf.ReadInt(); __f1.Add(__k1, __v1); } } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field2 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field3 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
        }

    }
}
